<?php

	 class UserRelation{
	 	
	 	private $id;
	 	private $idFriend;
	 	private $idGroup;
	 	private $date;
	 	
	 	function _construct($id,$idFriend,$idGroup,$date){
	 		$this -> id			= $id;
	 		$this -> idFriend	= $idFriend;
	 		$this -> idGroup	= $idGroup;
	 		$this -> date		= $date;
	 		
	 	}
	 	
	 	function getId(){
	 		return $this -> id;
	 	}
	 	
	 	function setIdFriend($idFriend){
	 		$this -> idFriend = $idFriend;
	 	}
	 	
	 	function getIdFriend(){
	 		return $this -> idFriend;
	 	}
	 	
	 	function setIdGroup($idGroup){
	 		$this -> idGroup = $idGroup;
	 	}
	 	
	 	function getIdGroup(){
	 		return $this -> idGroup;
	 	}
	 	
	 	function setDate($date){
	 		$this -> date = $date;
	 	}
	 	
	 	function getDate(){
	 		return $this -> date;
	 	}
	 	
	 	function getUserRelation($db,$id){
	 		
	 		$result=$db->query("SELECT * FROM user_relation WHERE ur_IDrelation = $id",2);
	
	 		
	 		$userRelation=new UserRelation(	$result[0]['ur_IDrelation'],
	 				$result[0]['ur_id_friend'],
	 				$result[0]['ur_id_group'],
	 				$result[0]['ur_date']);
	 			
	 		return $userRelation;
	 		
	 	}
	 	
	 	function insert($db,$UserRelation){
	 		
	 		$idFriend	= $UserRelation -> getIdFriend();
	 		$idGroup	= $UserRelation -> getIdGroup();
	 		
	 		$result= $db->insert("INSERT INTO user_relation
	 							 (ur_id_friend,ur_id_group,ur_date)
	 							 VALUES($idFriend,$idGroup,now())");
	 		return $result; 		
	 		
	 	}
	 	
	 	function delete($db,$UserRelation){
	 		$id 	= $UserRelation -> getId();
	 		$result = $db->delete("DELETE FROM user_relation WHERE ur_IDrelation= $id");
	 		return $result;
	 	}
	 	
	 	function update($db,$UserRelation){
	 		$id 		= $UserRelation -> getId();
	 		$idFriend	= $UserRelation -> getIdFriend();
	 		$idGroup	= $UserRelation -> getIdGroup();
	 		$idDate		= $UserRelation -> getDate();
	 		
	 		$result = $db->update("UPDATE user_relation SET
								   ur_id_friend= $idFriend,
	 							   ur_id_group= $idGroup,
	 							   ur_date= $idDate
	 							   WHERE ur_IDrelation= $id");
	 		return $result;
	 	}
	 	
	 }
?>